package com.zzyl.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/redis")
public class RedisTestController {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @GetMapping("/test")
    public String testRedis() {
        try {
            redisTemplate.opsForValue().set("test-key", "test-value");
            String value = (String) redisTemplate.opsForValue().get("test-key");
            return "Redis连接成功，获取到值: " + value;
        } catch (Exception e) {
            return "Redis连接失败: " + e.getMessage();
        }
    }
}